{{ header }}
<div class="site-breadcrumb">
  <div class="container">
    <ul class="breadcrumb">
      {% for breadcrumb in breadcrumbs %}
      <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
      {% endfor %}
    </ul>
  </div>
</div>
<div class="page-main user-center">
  <div class="container">
    <div class="row">
      {{ column_left }}
      {% if column_left and column_right %}
      {% set class = 'col-sm-6' %}
      {% elseif column_left or column_right %}
      {% set class = 'col-sm-9' %}
      {% else %}
      {% set class = 'col-sm-12' %}
      {% endif %}
      <div id="content" class="{{ class }}">
        {{ content_top }}
        {% if error_warning %}
        <div class="alert alert-danger alert-dismissible"><i class="icon-warning"></i> {{ error_warning }}</div>
        {% endif %}
        <h1 class="heading">{{ text_account_setting }}</h1>
        <ul class="nav nav-tabs">
          <li class="active"><a href="{{ profile }}">{{ text_account_profile }}</a></li>
          <li><a href="{{ address }}">{{ text_account_address }}</a></li>
          <li><a href="{{ password }}">{{ text_account_password }}</a></li>
          <li><a href="{{ newsletter }}">{{ text_newsletter }}</a></li>
        </ul>
        <form action="{{ action }}" method="post" enctype="multipart/form-data" class="form-horizontal tab-content">
          <fieldset>
            <legend class="hidden">{{ text_your_details }}</legend>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="input-email">{{ entry_email }}</label>
              <div class="col-sm-10">
                <p class="form-control-static">{{ email }}</p>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="input-fullname">{{ entry_fullname }}</label>
              <div class="col-sm-10">
                <input type="text" name="fullname" value="{{ fullname }}" placeholder="{{ entry_fullname }}" id="input-fullname" class="form-control" />
                {% if error_fullname %}
                <div class="text-danger">{{ error_fullname }}</div>
                {% endif %}
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="input-telephone">{{ entry_telephone }}</label>
              <div class="col-sm-10">
                <input type="tel" name="telephone" value="{{ telephone }}" placeholder="{{ entry_telephone }}" id="input-telephone" class="form-control" />
                {% if error_telephone %}
                <div class="text-danger">{{ error_telephone }}</div>
                {% endif %}
              </div>
            </div>
            {% for custom_field in custom_fields %}
            {% if custom_field.type == 'select' %}
            <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
              <label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
              <div class="col-sm-10">
                <select name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control">
                  <option value="">{{ text_select }}</option>
                  {% for custom_field_value in custom_field.custom_field_value %}
                  {% if account_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id == account_custom_field[custom_field.custom_field_id] %}
                  <option value="{{ custom_field_value.custom_field_value_id }}" selected="selected">{{ custom_field_value.name }}</option>
                  {% else %}
                  <option value="{{ custom_field_value.custom_field_value_id }}">{{ custom_field_value.name }}</option>
                  {% endif %}
                  {% endfor %}
                </select>
                {% if error_custom_field[custom_field.custom_field_id] %}
                <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                {% endif %}
              </div>
            </div>
            {% endif %}
            {% if custom_field.type == 'radio' %}
            <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
              <label class="col-sm-2 control-label">{{ custom_field.name }}</label>
              <div class="col-sm-10">
                <div>
                  {% for custom_field_value in custom_field.custom_field_value %}
                  <div class="radio">
                    {% if account_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id == account_custom_field[custom_field.custom_field_id] %}
                    <label>
                      <input type="radio" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{{ custom_field_value.custom_field_value_id }}" checked="checked" />
                      {{ custom_field_value.name }}</label>
                    {% else %}
                    <label>
                      <input type="radio" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{{ custom_field_value.custom_field_value_id }}" />
                      {{ custom_field_value.name }}</label>
                    {% endif %}
                  </div>
                  {% endfor %}
                </div>
                {% if error_custom_field[custom_field.custom_field_id] %}
                <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                {% endif %}
              </div>
            </div>
            {% endif %}
            {% if custom_field.type == 'checkbox' %}
            <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
              <label class="col-sm-2 control-label">{{ custom_field.name }}</label>
              <div class="col-sm-10">
                <div>
                  {% for custom_field_value in custom_field.custom_field_value %}
                  <div class="checkbox">
                    {% if account_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id in account_custom_field[custom_field.custom_field_id] %}
                    <label>
                      <input type="checkbox" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}][]" value="{{ custom_field_value.custom_field_value_id }}" checked="checked" />
                      {{ custom_field_value.name }}</label>
                    {% else %}
                    <label>
                      <input type="checkbox" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}][]" value="{{ custom_field_value.custom_field_value_id }}" />
                      {{ custom_field_value.name }}</label>
                    {% endif %}
                  </div>
                  {% endfor %}
                </div>
                {% if error_custom_field[custom_field.custom_field_id] %}
                <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                {% endif %}
              </div>
            </div>
            {% endif %}
            {% if custom_field.type == 'text' %}
            <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
              <label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
              <div class="col-sm-10">
                <input type="text" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if account_custom_field[custom_field.custom_field_id] %}{{ account_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}" placeholder="{{ custom_field.name }}" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control" />
                {% if error_custom_field[custom_field.custom_field_id] %}
                <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                {% endif %}
              </div>
            </div>
            {% endif %}
            {% if custom_field.type == 'textarea' %}
            <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
              <label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
              <div class="col-sm-10">
                <textarea name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" rows="5" placeholder="{{ custom_field.name }}" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control">{% if account_custom_field[custom_field.custom_field_id] %}{{ account_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}</textarea>
                {% if error_custom_field[custom_field.custom_field_id] %}
                <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                {% endif %}
              </div>
            </div>
            {% endif %}
            {% if custom_field.type == 'file' %}
            <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
              <label class="col-sm-2 control-label">{{ custom_field.name }}</label>
              <div class="col-sm-10">
                <button type="button" id="button-custom-field{{ custom_field.custom_field_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default"><i class="icon-upload"></i> {{ button_upload }}</button>
                <input type="hidden" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if account_custom_field[custom_field.custom_field_id] %}{{ account_custom_field[custom_field.custom_field_id] }} {% endif %}" />
                {% if error_custom_field[custom_field.custom_field_id] %}
                <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                {% endif %}
              </div>
            </div>
            {% endif %}
            {% if custom_field.type == 'date' %}
            <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
              <label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
              <div class="col-sm-10">
                <div class="input-group date">
                  <input type="text" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if account_custom_field[custom_field.custom_field_id] %}{{ account_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}" placeholder="{{ custom_field.name }}" data-date-format="YYYY-MM-DD" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control" />
                  <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="icon-calendar"></i></button>
                  </span></div>
                {% if error_custom_field[custom_field.custom_field_id] %}
                <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                {% endif %}
              </div>
            </div>
            {% endif %}
            {% if custom_field.type == 'time' %}
            <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
              <label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
              <div class="col-sm-10">
                <div class="input-group time">
                  <input type="text" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if account_custom_field[custom_field.custom_field_id] %}{{ account_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}" placeholder="{{ custom_field.name }}" data-date-format="HH:mm" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control" />
                  <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="icon-calendar"></i></button>
                  </span></div>
                {% if error_custom_field[custom_field.custom_field_id] %}
                <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                {% endif %}
              </div>
            </div>
            {% endif %}
            {% if custom_field.type == 'time' %}
            <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
              <label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
              <div class="col-sm-10">
                <div class="input-group datetime">
                  <input type="text" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if account_custom_field[custom_field.custom_field_id] %}{{ account_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}" placeholder="{{ custom_field.name }}" data-date-format="YYYY-MM-DD HH:mm" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control" />
                  <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="icon-calendar"></i></button>
                  </span></div>
                {% if error_custom_field[custom_field.custom_field_id] %}
                <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                {% endif %}
              </div>
            </div>
            {% endif %}
            {% endfor %}
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-primary">{{ button_submit }}</button>
              </div>
            </div>
          </fieldset>
        </form>
        {{ content_bottom }}
      </div>
      {{ column_right }}
    </div>
  </div>
</div>
<script type="text/javascript"><!--
// Sort the custom fields
$('.form-group[data-sort]').detach().each(function() {
	if ($(this).attr('data-sort') >= 0 && $(this).attr('data-sort') <= $('.form-group').length) {
		$('.form-group').eq($(this).attr('data-sort')).before(this);
	}

	if ($(this).attr('data-sort') > $('.form-group').length) {
		$('.form-group:last').after(this);
	}

	if ($(this).attr('data-sort') == $('.form-group').length) {
		$('.form-group:last').after(this);
	}

	if ($(this).attr('data-sort') < -$('.form-group').length) {
		$('.form-group:first').before(this);
	}
});
//--></script>
<script type="text/javascript"><!--
$('button[id^=\'button-custom-field\']').on('click', function() {
	var element = this;

	$('#form-upload').remove();

	$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" /></form>');

	$('#form-upload input[name=\'file\']').trigger('click');

	if (typeof timer != 'undefined') {
    	clearInterval(timer);
	}

	timer = setInterval(function() {
		if ($('#form-upload input[name=\'file\']').val() != '') {
			clearInterval(timer);

			$.ajax({
				url: 'index.php?route=tool/upload',
				type: 'post',
				dataType: 'json',
				data: new FormData($('#form-upload')[0]),
				cache: false,
				contentType: false,
				processData: false,
				beforeSend: function() {
					$(element).button('loading');
				},
				complete: function() {
					$(element).button('reset');
				},
				success: function(json) {
					$(element).parent().find('.text-danger').remove();

					if (json['error']) {
						$(element).parent().find('input').after('<div class="text-danger">' + json['error'] + '</div>');
					}

					if (json['success']) {
						alert(json['success']);

						$(element).parent().find('input').val(json['code']);
					}
				},
				error: function(xhr, ajaxOptions, thrownError) {
					alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
				}
			});
		}
	}, 500);
});
//--></script>
<script type="text/javascript"><!--
$('.date').datetimepicker({
	language: '{{ datepicker }}',
	pickTime: false
});

$('.datetime').datetimepicker({
	language: '{{ datepicker }}',
	pickDate: true,
	pickTime: true
});

$('.time').datetimepicker({
	language: '{{ datepicker }}',
	pickDate: false
});
//--></script>
{{ footer }}
